package cn.scu.ne04jdemo.service.imp;

import cn.scu.ne04jdemo.dao.UseRightDao;
import cn.scu.ne04jdemo.entitiy.OwnershipRight;
import cn.scu.ne04jdemo.entitiy.UseRight;
import cn.scu.ne04jdemo.service.UseRightService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UseRightServiceImp extends ServiceImpl<UseRightDao, UseRight> implements UseRightService {
    private final UseRightDao useRightDao;

    public UseRightServiceImp(UseRightDao useRightDao) {
        this.useRightDao = useRightDao;
    }

    @Override
    public List<UseRight> queryUseRightByParam(Map<String, String> params) {
        Map<String, Object> map = new HashMap<>();
        if (params != null) {
            if (params.containsKey("agentName"))
                map.put("agentName", params.get("agentName"));
            if (params.containsKey("startTime"))
                map.put("startTime", Date.valueOf(params.get("startTime").replaceAll("/", "-")));
            if (params.containsKey("endTime"))
                map.put("endTime", Date.valueOf(params.get("endTime").replaceAll("/", "-")));
            if (params.containsKey("hashValue"))
                map.put("hashValue", params.get("hashValue"));
        }
        return useRightDao.queryUseRightListByParam(map);
    }
}
